Component({
  data: {
    isDarkMode: false
  },

  lifetimes: {
    attached() {
      const isDark = wx.getStorageSync('darkMode') || false;
      this.setData({ isDarkMode: isDark });
    }
  },

  methods: {
    toggleDarkMode(e) {
      const isDark = e.detail.value;
      wx.setStorageSync('darkMode', isDark);
      const app = getApp();
      app.globalData.isDarkMode = isDark;

      // 触发事件通知页面更新
      this.triggerEvent('modechange', { isDarkMode: isDark });
    }
  }
});
